package com.example.server.service.impl;

import com.example.server.mapper.MyMenuMapper;
import com.example.server.pojo.MyMenu;
import com.example.server.service.MyMenuService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class MyMenuServiceImpl implements MyMenuService {
    @Resource
    private MyMenuMapper myMenuMapper;

    @Override
    public List<MyMenu> allMenu() {
        List<MyMenu> myMenus = parentMenu();
        myMenus.forEach((parentMenu) -> {
            Integer parentId = parentMenu.getId();
            List<MyMenu> children = subMenu(parentId);
            parentMenu.setChildren(children);
        });
        return myMenus;
    }

    @Override
    public List<MyMenu> parentMenu() {
        return myMenuMapper.parentMenu();
    }

    @Override
    public List<MyMenu> subMenu(Integer parentId) {
        return myMenuMapper.subMenu(parentId);
    }
}
